package com.xz.example.util;

import com.xz.example.model.dark_model.DarkAttachment;
import com.xz.example.model.dark_model.DarkWeeklReport;

import java.io.IOException;
import java.rmi.server.ExportException;
import java.util.*;

/**
 * @author 张志航     
 * @version V1.0.0
 * @projectName design_mode
 * @title     PrototypeManager   
 * @package    com.xz.example.util  
 * @date   2019/12/2 11:54  
 * @explain
 */
public class PrototypeManager {

    private Hashtable<String,DarkWeeklReport> hashtable = new Hashtable(); // 使用HashTable存储原型对象,线程安全

    public PrototypeManager() {
        DarkWeeklReport defaultWeekly = new DarkWeeklReport();
        defaultWeekly.setName("默认周报模板");
        defaultWeekly.setDate("2019.12.02");
        defaultWeekly.setContent("默认内容");
        DarkAttachment defaultAttachment = new DarkAttachment();
        defaultAttachment.setName("默认附件");
        defaultWeekly.setAttachment(defaultAttachment);
        hashtable.put("default",defaultWeekly);
    }

    public void add(String key, DarkWeeklReport darkWeeklReport){
        hashtable.put(key,darkWeeklReport);
    }


    public DarkWeeklReport get(String key) throws IOException, ClassNotFoundException {
        return hashtable.get(key).deepClone();
    }

}
